import { BasicMarker } from '../../js/BasicMarker.js';
import { BasicMarkers } from '../../js/BasicMarkers.js';
import { getMarkerIcon } from '../../js/icon.js';
import { getGisEntityZyData } from '@gis/lib/api';
import { handleCommonResult } from '@gis/lib/utils/resolver';
import { useUserInfoStore } from '@gis/lib/pinia/userInfo.js';
import { openFireStationDetailsDialog } from '../../../../views/fire-hazard/opt.js';
import vbus from '@gis/lib/utils/vBus.js';

class Marker extends BasicMarker {
  constructor({ map, data }) {
    super({ map, data });
    this.type = 'cyxfzzd';
    super.create();
  }
  getIcon() {
    return getMarkerIcon(this.type);
  }
  getIconOption(icon) {
    return {
      content: `<div style="width: 56px;height: 97px;background: url(${icon}) center center no-repeat;background-size: 100% 100%"></div>`,
      offset: new AMap.Pixel(0, 0),
    };
  }
  onClick() {
    openFireStationDetailsDialog(this.data);
  }
  onRightClick(e) {
    vbus.$emit('xfzRightClick', this.data);
  }
}

export default class Cyxfzzd extends BasicMarkers {
  constructor({ map }) {
    super();
    this.map = map;
  }
  createMarker(data) {
    return new Marker({ map: this.map, data });
  }
  async getDataAsync() {
    const { area_code } = useUserInfoStore();
    const params = {
      type: '6',
      area_code: area_code,
    };
    const res = handleCommonResult(await getGisEntityZyData(params));
    return res
      .filter((item) => item.type_code == '6_22')
      .map((item) => Object.assign({}, item, { lnglat: [item.longitude, item.latitude] }));
  }
}
